
/**************************************************START OF FILE*****************************************************/





/*------------------------------------------------------------------------------------------------------------------
Includes
*/
#include "xBSP_Gpio.h"


/*------------------------------------------------------------------------------------------------------------------
Macros
*/


/*------------------------------------------------------------------------------------------------------------------
Variables
*/



/*
********************************************************************************************************************
@ Brief  : GPIO Init: led key codec ......

@ Param  : NONE

@ Return : NONE

@ Author : lyc

@  Date  : 2020 - 04 - 02
********************************************************************************************************************
*/
void xBSP_GPIO_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStruct = {0};

    /* GPIO Ports Clock Enable */
    __HAL_RCC_GPIOB_CLK_ENABLE();
    __HAL_RCC_GPIOC_CLK_ENABLE();          
    __HAL_RCC_GPIOD_CLK_ENABLE();    
    __HAL_RCC_GPIOH_CLK_ENABLE();
    __HAL_RCC_GPIOE_CLK_ENABLE();

	/****************************************************************************
	* IO Out
	*/
    /*Configure GPIO pins : PE7 PE8 PE9 */
    GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
    /*Configure GPIO pin Output Level */
    HAL_GPIO_WritePin(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9, GPIO_PIN_SET);

    //PB2
    GPIO_InitStruct.Pin = GPIO_PIN_2;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_PULLDOWN;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_RESET);

    /*
    	LCD_PWR:	PB7
    	LCD_RST:	PB6
    	LCD_DC:		PB4
    	LCD_CS:		PD7
    */
    GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7, GPIO_PIN_RESET);

    GPIO_InitStruct.Pin = GPIO_PIN_7;
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_RESET);
    

	/****************************************************************************
	* IO IN
	*/
    GPIO_InitStruct.Pin = GPIO_PIN_13;         
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;    
    GPIO_InitStruct.Pull = GPIO_PULLDOWN;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;   
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 ;	
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;    
    GPIO_InitStruct.Pull = GPIO_PULLDOWN;      
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;   
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);   
}

/*
********************************************************************************************************************
@ Brief  : 读取按键IO情况: 音量按键0~3 Preset:4~13 Sample:14~29  (按键所占用位)

@ Param  : NONE

@ Return : NONE

@ Author : lyc
********************************************************************************************************************
*/
uint32_t xBSP_IO_Input_GetData(void)
{
	uint32_t keyCurrent = 0;   //初始化0 表示都没有按下

	READ_KEY0()  ? (keyCurrent&=(~NUM_KEY0)):(keyCurrent|=NUM_KEY0);
    READ_KEY1()  ? (keyCurrent&=(~NUM_KEY1)):(keyCurrent|=NUM_KEY1);
    READ_KEY2()  ? (keyCurrent&=(~NUM_KEY2)):(keyCurrent|=NUM_KEY2);
    !READ_KEY3()  ? (keyCurrent&=(~NUM_KEY3)):(keyCurrent|=NUM_KEY3);

	return keyCurrent;
}




/****************************************************END OF FILE*****************************************************/
